//
//  ChoosePersonCell.m
//  IpadTestB
//
//  Created by edianzu on 2017/7/6.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ChoosePersonCell.h"
@interface ChoosePersonCell()
@property(nonatomic,assign)NSInteger  indexp;
@end
@implementation ChoosePersonCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createUI];
    }
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}

-(void)createUI{
    self.selectImage = [[UIImageView alloc]init];
    self.selectImage.image = [UIImage imageNamed:@"selectImg"];
    [self.contentView addSubview:self.selectImage];
    [self.selectImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(25*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(25*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
    self.label = [[UILabel alloc]init];
    self.label.textColor = [UIColor blackColor];
    self.label.font = [UIFont systemFontOfSize:20*AutoScaleHorizontal];
//    self.label.text = @"全选";
    [self.contentView addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selectImage.mas_right).with.offset(10*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(150*AutoScaleHorizontal, 25*AutoScaleVertical));
    }];
    
    self.coverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.coverBtn.backgroundColor = [UIColor clearColor];
    [self.coverBtn addTarget:self action:@selector(pressCover) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.coverBtn];
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.contentView);
    }];
    
}

-(void)relayoutCellWithModel:(ChildModel *)model andIndex:(NSInteger)indexpath{
    self.indexp = indexpath;
    self.label.text = model.ChildName;
    if ([model.isSelected isEqualToString:@"1"]) {
        self.coverBtn.selected = YES;
        self.selectImage.image = [UIImage imageNamed:@"selectImgS"];
    }else{
        self.coverBtn.selected = NO;
        self.selectImage.image = [UIImage imageNamed:@"selectImg"];
    }
}

-(void)pressCover{
    NSLog(@"cover");
//    self.coverBtn.selected = !self.coverBtn.selected;
    if (self.coverBtn.selected ==YES) {
//        self.selectImage.image = [UIImage imageNamed:@"selectImgS"];
        self.callChange(@"1", self.indexp);
    }else{
//        self.selectImage.image = [UIImage imageNamed:@"selectImg"];
        self.callChange(@"0", self.indexp);
    }
    
}


@end
